package org.zxyj.system.server.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zxyj.core.constants.Dict;
import org.zxyj.system.dao.ISysParamsDao;
import org.zxyj.system.domain.SysParams;
import org.zxyj.system.server.ISysParamsService;
import org.zxyj.core.entity.Pagination;

/**
 * 系统参数实现类
    * @ClassName: SysParamsServiceImpl
    * @author liuyong
    * @date 2016年7月7日
 */
@Service
public class SysParamsServiceImpl implements ISysParamsService{
	protected Logger logger = LoggerFactory.getLogger(this.getClass());
	@Autowired
	private ISysParamsDao dao;
	
	public List<SysParams> listEntitiesByKey(String key) {
		Map<String, Object> criteria = new HashMap<String, Object>();
		criteria.put("key", key);
		criteria.put("orderBy", true);
		criteria.put("status", Dict.STATUS.ON);
		return dao.find(criteria);
	}
	
	public List<SysParams> listEntitiesByKeyDesc(String key) {
		Map<String, Object> criteria = new HashMap<String, Object>();
		criteria.put("key", key);
		criteria.put("orderByDesc", true);
		criteria.put("status", Dict.STATUS.ON);
		return dao.find(criteria);
	}
	
	public List<SysParams> listEntities(Map<String, Object> criteria) {
		logger.debug("listing entities refer to criteria, param: [{}]", criteria);

		if (null == criteria) {
			criteria = new HashMap<String, Object>();
		}
		criteria.put("orderBy", true);
		criteria.put("status", Dict.STATUS.ON);
		return dao.find(criteria);
	}
	
	public List<SysParams> listEntitiesByDesc(Map<String, Object> criteria) {
		logger.debug("listing entities refer to criteria, param: [{}]", criteria);

		if (null == criteria) {
			criteria = new HashMap<String, Object>();
		}
		criteria.put("orderByDesc", true);
		criteria.put("status", Dict.STATUS.ON);
		return dao.find(criteria);
	}

	public Pagination listEntities(Map<String, Object> criteria, Pagination pagination) {
		logger.debug("listing entities refer to criteria and pagination, param: criteria[{}], pagination[{}]", criteria,
				pagination);
		if (null == criteria) {
			criteria = new HashMap<String, Object>();
		}
		criteria.put("pagination", pagination);
		List<SysParams> entities = dao.find(criteria);
		Long totalCount = dao.count(criteria);
		if (null == pagination) {
			pagination = new Pagination();
		}
		pagination.setTotal(totalCount);
		pagination.setDatas(entities);
		return pagination;
	}

	public SysParams findEntity(Map<String, Object> criteria) {
		logger.debug("find role refer to criteria, param: criteria[{}]", criteria);

		if (null == criteria) {
			// 参数错误
			return null;
		}
		return dao.findById(criteria);
	}

}
